package gui;

import gui.listener.InputListenerFactory;
import handwritten.gesture.HandInputManager;
import handwritten.gesture.MultiGesture;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ComponentListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;

import javax.swing.JPanel;




public class JPInputPanel extends JPanel implements InputPanel {
	
	
	
	
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public JPInputPanel(GUIMaster guiMaster) {
		this.setBackground(new Color(255,255,255));
		
		
		addMouseListener((MouseListener)InputListenerFactory.getInstance().createInputListener(MouseListener.class, guiMaster));
		addMouseMotionListener((MouseMotionListener)InputListenerFactory.getInstance().createInputListener(MouseMotionListener.class, guiMaster));
		addComponentListener((ComponentListener)InputListenerFactory.getInstance().createInputListener(ComponentListener.class, guiMaster));
	
	}


	public void paint(Graphics g){
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
	    RenderingHints rh = new RenderingHints(
	             RenderingHints.KEY_TEXT_ANTIALIASING,
	             RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	    g2.setRenderingHints(rh);
				
	    
	    HandInputManager.getInstance().getInputGrid().paint(g2);
	    
	    
	    ArrayList<MultiGesture> gest=HandInputManager.getInstance().getLetters();
	    if(gest.size()!=0)
	    	gest.get(gest.size()-1).paint(g2);
	    HandInputManager.getInstance().getGestureCandidate().paint(g2);
	   	    	   
	}


}
